Skip to content

Go: Check more things while running tests #19491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

owen-mc
Copy link
Contributor

@owen-mc owen-mc commented May 14, 2025

This PR adds the following flags when we run tests: --fail-on-trap-errors, --check-undefined-labels, --check-unused-labels, --check-repeated-labels, --check-redefined-labels, --check-use-before-definition. There are also two extractor fixes to make tests pass with these flags:

  1. Avoid making unused labels in certain situations.
  2. Fix a db inconsistency on Windows by making the Go extractor use "C:/" for the drive root instead of "C:", so it matches up with the XML extractor (which we use for HTML files).

@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label May 14, 2025
@github-actions github-actions bot added the Go label May 14, 2025
@owen-mc
Copy link
Contributor Author

owen-mc commented May 15, 2025

The CI has highlighted a db inconsistency that only happens on windows: the container parent of "C:/a" is recorded as both "C:/" and "C:". This only happens in tests with html files, hence it must be related to the xml extractor.

@owen-mc owen-mc force-pushed the go/add-test-flags branch 3 times, most recently from c42710a to afc4bf3 Compare May 20, 2025 02:24
@owen-mc owen-mc marked this pull request as ready for review May 20, 2025 12:00
@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 12:00
@owen-mc owen-mc requested a review from a team as a code owner May 20, 2025 12:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds more validation flags to the CodeQL test command and refactors the Go extractor’s path handling and nil checks.

  • Introduces rawPath/canonicalPath in extractFileInfo to normalize file paths.
  • Simplifies nil checks in extractExpr, extractStmt, and extractDecl by moving them to the top.
  • Updates test runner flags in Makefile and adjusts GitHub Actions Windows runner configuration.
  • Aligns greet.go import alias with updated definitions expected output.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
go/ql/test/query-tests/definitions/greet.go Renamed import to myfmt and updated print call
go/ql/test/query-tests/definitions/definitions.expected Added new definition entry for myfmt
go/extractor/extractor.go Introduced rawPath/canonicalPath, refactored nil checks
go/Makefile Added new --check-* flags to codeql test run
.github/workflows/go-tests-other-os.yml Changed runs-on from windows-latest-xl to windows-latest
Comments suppressed due to low confidence (1)

go/Makefile:57

  • Remove the --check-unused-labels flag, as noted in the PR description, to prevent unintended test failures caused by trap errors and ensure consistency with the intended test configuration.
codeql test run -j0 ql/test --search-path .. --consistency-queries ql/test/consistency --compilation-cache=$(cache) --dynamic-join-order-mode=$(rtjo) --check-databases --fail-on-trap-errors --check-undefined-labels --check-unused-labels --check-repeated-labels --check-redefined-labels --check-use-before-definition

if path != "/" {
parentPath = path
}
parentPath = rawPath
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditionally assigning parentPath = rawPath will make the next iteration build rawPath differently when rawPath is empty (root). Consider guarding this assignment for root paths (e.g. only set parentPath when rawPath is non-empty) to preserve correct canonical paths.

Suggested change
parentPath = rawPath
if rawPath != "" {
parentPath = rawPath
}

Copilot uses AI. Check for mistakes.

owen-mc added 6 commits May 20, 2025 13:13
This makes the test slightly more thorough.
In go, an interface with value nil does not compare equal to nil. This
is known as "typed nils". So our existing nil checks weren't working,
which shows why we needed more nil checks inside the type switches. The
solution is to explicitly check for each type we care about.
@owen-mc owen-mc force-pushed the go/add-test-flags branch from 85d5922 to 83cd349 Compare May 20, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant